package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.CouponMapper;
import com.qf.entitys.Coupon;
import com.qf.service.CouponService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class CouponServiceImpl implements CouponService {

    @Resource
    private CouponMapper mapper;

    @Override
    public int deleteByPrimaryKey(Integer couponId) {
        return 0;
    }

    @Override
    public int insert(Coupon record) {
        return 0;
    }

    @Override
    public int insertSelective(Coupon record) {
        return mapper.insertSelective(record);
    }

    @Override
    public Coupon selectByPrimaryKey(Integer couponId) {
        return mapper.selectByPrimaryKey(couponId);
    }

    @Override
    public int updateByPrimaryKeySelective(Coupon record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Coupon record) {
        return 0;
    }

    @Override
    public PageInfo<Coupon> selectAllByBidCoupons(Integer id, Integer pageindex) {
        PageHelper.startPage(pageindex,10);
        List<Coupon> coupons=mapper.selectAllByBidCoupons(id);
        List<Coupon> couponList=new ArrayList<>();
        for (Coupon coupon:coupons) {
            if(coupon.getStatus()!=2) {
                couponList.add(coupon);
            }
        }
        PageInfo<Coupon> pageInfo=new PageInfo<>(couponList);
        return pageInfo;
    }

    @Override
    public PageInfo<Coupon> selectAllByBidCouponsAndCouponName(Integer id, Integer pageindex, String name) {
        PageHelper.startPage(pageindex,10);
        String Name="%"+name+"%";
        List<Coupon> coupons=mapper.selectAllByBidCouponsAndName(id,Name);
        List<Coupon> couponList=new ArrayList<>();
        for (Coupon coupon:coupons) {
            if(coupon.getStatus()!=2) {
                couponList.add(coupon);
            }
        }
        PageInfo<Coupon> pageInfo=new PageInfo<>(couponList);
        return pageInfo;
    }

    @Override
    public List<Coupon> selectByByBidAndUserId(Integer bid, Integer userid) {
        return mapper.selectByByBidAndUserId(bid,userid);
    }
}
